<template>
    <div class="app-container">
        <a-card>
            <BasicTable ref="tableRef" :params="params" :selectbox="false" :columns="columns" :query="query">
                <template #form>
                    <a-form-item label="企业名称" name="name">
                        <a-input v-model:value="params.name" placeholder="请输入企业名称" />
                    </a-form-item>
                </template>
                <template #button>
                    <a-button v-permission="'system:firm:add'" type="primary" @click="open(modalRef)">
                        <template #icon>
                            <PlusOutlined />
                        </template>
                        新增
                    </a-button>
                </template>
                <template #table="{ body }">
                    <template v-if="body.column.key === 'status'">
                        <Switch v-model:checked="body.record.status" @change="switchChange(updateStatus, body.record.id, $event)" />
                    </template>
                    <template v-if="body.column.key === 'action'">
                        <a-button v-permission="'system:firm:edit'" type="link" @click="open(modalRef, body.record)">
                            <template #icon>
                                <EditOutlined />
                            </template>
                            编辑
                        </a-button>
                        <a-popconfirm title="确定要删除吗?" @confirm="del(deleteById, body.record.id, tableRef)">
                            <a-button v-permission="'system:firm:delete'" type="link">
                                <template #icon>
                                    <DeleteOutlined />
                                </template>
                                删除
                            </a-button>
                        </a-popconfirm>
                    </template>
                </template>
            </BasicTable>
        </a-card>
        <Modal ref="modalRef" @close="refresh(tableRef)" />
    </div>
</template>
<script setup name="FirmModule">
import { reactive, ref } from 'vue'
import { query, deleteById, updateStatus } from '/@/api/System/Firm'
import { DeleteOutlined, PlusOutlined, EditOutlined } from '@ant-design/icons-vue'
import { useBasicTable } from '@iframe/tools/mixins/BasicTableMixins'
import { BasicTable, Switch } from '@iframe/tools/components'
import Modal from './Modal.vue'

const { refresh, del, open, switchChange } = useBasicTable()
const tableRef = ref()
const modalRef = ref()
const params = reactive({
    name: null
})
const columns = [
    {
        title: '企业名称',
        dataIndex: 'name',
        key: 'name',
        width: 300
    },
    {
        title: '联系人',
        dataIndex: 'linkMan',
        key: 'linkMan',
        align: 'center',
        width: 120
    },
    {
        title: '联系电话',
        dataIndex: 'linkTelphone',
        key: 'linkTelphone',
        align: 'center',
        width: 150
    },
    {
        title: '企业描述',
        dataIndex: 'des',
        key: 'des'
    },
    {
        title: '状态',
        dataIndex: 'status',
        key: 'status',
        width: 100,
        align: 'center'
    },
    {
        title: '操作',
        key: 'action',
        align: 'center',
        width: 200
    }
]
</script>
